package com.huichenghe.xinlvsh01.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huichenghe.xinlvsh01.DataEntites.CustomRemindEntity;
import com.huichenghe.xinlvsh01.R;

import java.util.ArrayList;

/**
 * Created by lixiaoning on 15-12-3.
 */
public class RemindCustomRecyclerAdapter extends RecyclerView.Adapter<RemindCustomRecyclerAdapter.MyViewHolder>
{
    public static final String TAG = RemindCustomRecyclerAdapter.class.getSimpleName();
    private Context mContext;
    private ArrayList<CustomRemindEntity> dataList;



    public RemindCustomRecyclerAdapter(Context mContext, ArrayList<CustomRemindEntity> dataList)
    {
        this.dataList = dataList;
        this.mContext = mContext;
    }


    // 加载布局文件，返回一个viewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_for_custom_remind, parent, false);
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position)
    {
        CustomRemindEntity customRemindEntity = dataList.get(position);
//        Log.i(TAG, "图片资源：" + customRemindEntity.getIcon() + "--" +
//                                 customRemindEntity.getTimes() + "--" +
//                                 customRemindEntity.getRepeats() + "--" +
//                                 customRemindEntity.getType());
        byte type = customRemindEntity.getType();

                switch (type)
                {
                    case (byte)0x01:
                        holder.mIcon.setImageResource(R.drawable.movement);
                        holder.mMotionType.setText(mContext.getString(R.string.movement_text));
                        break;
                    case (byte)0x02:
                        holder.mIcon.setImageResource(R.drawable.eat);
                        holder.mMotionType.setText(mContext.getString(R.string.eat_foot));
                        break;
                    case (byte)0x03:
                        holder.mIcon.setImageResource(R.drawable.dringk);
                        holder.mMotionType.setText(mContext.getString(R.string.drink));
                        break;
                    case (byte)0x04:
                        holder.mIcon.setImageResource(R.drawable.medicine);
                        holder.mMotionType.setText(mContext.getString(R.string.take_medicine));
                        break;
                    case (byte)0x05:
                        holder.mIcon.setImageResource(R.drawable.sleep);
                        holder.mMotionType.setText(mContext.getString(R.string.sleep_text_choose));
                        break;
                    case (byte)0x06:
                        holder.mIcon.setImageResource(R.drawable.custom_remind_icon);
                        break;
                }



        holder.remindTime.setText(customRemindEntity.getTimes());
        holder.remindRepeat.setText(customRemindEntity.getRepeats());




    }

    @Override
    public int getItemCount()
    {
        return dataList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {
        ImageView mIcon;
        TextView mMotionType, remindTime, remindRepeat;
        public MyViewHolder(View itemView)
        {
            super(itemView);
            mIcon = (ImageView)itemView.findViewById(R.id.icon_type_l);
            mMotionType = (TextView)itemView.findViewById(R.id.motion_type);
            remindTime = (TextView)itemView.findViewById(R.id.remind_time);
            remindRepeat = (TextView)itemView.findViewById(R.id.remind_repeat);


        }
    }
}
